package com.example.book_system.model;

import lombok.Data;

@Data
public class Result {
    private ResultStatus status;
    private String errorMessage;
    private Object data;

    /**
     * 业务成功响应
     * @param data
     * @return
     */
    public static Result success(Object data){
        Result result = new Result();
        result.setData(data);
        result.setStatus(ResultStatus.SUCCESS);
        result.setErrorMessage("");
        return result;
    }

    /**
     * 业务未成功响应
     * @param message
     * @return
     */
    public static Result fail(String message){
        Result result = new Result();
        result.setData("");
        result.setStatus(ResultStatus.FAIL);
        result.setErrorMessage(message);
        return result;
    }

    /**
     * 用户未登录
     * @return
     */
    public static Result unLogin(){
        Result result = new Result();
        result.setData(null);
        result.setStatus(ResultStatus.UNLOGIN);
        result.setErrorMessage("用户未登录");
        return result;
    }


}
